package org.vidyakiran.app.client.view;

import org.vidyakiran.app.client.service.suggestion.ItemSuggestOracle;

import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.control.LargeMapControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class VolunteerView {
	public static String CITY = "CITY";
	public static String LOCATION = "LOCATION";
	public static String INTEREST = "INTEREST";
	//private FlexTable mainPanel;
	private VerticalPanel baseVerticalPanel = new VerticalPanel();
	
	private HorizontalPanel topHorizontalPanel = new HorizontalPanel();
	private MapWidget map = new MapWidget();
	private VerticalPanel mapsPanel = new VerticalPanel();
	private VerticalPanel searchCriteriaPanel= new VerticalPanel();
	private FlexTable searchCriteriaTable = new FlexTable();
	
	private HorizontalPanel bottomHorizontalPanel = new HorizontalPanel();
	
	private VerticalPanel resultsPanel = new VerticalPanel();
	private FlexTable searchResultsTable = new FlexTable();
	
	private VerticalPanel topRatedStuff = new VerticalPanel();
	private FlexTable topActivitiesTable = new FlexTable();
	private FlexTable activeVolunteersTable = new FlexTable();
	
	
	private SuggestBox citySuggestBox; 
	private SuggestBox locationSuggestBox;
	private SuggestBox interestSuggestBox;
	
	private TextArea infoTextArea;
	private Label findlabel;
	private ListBox choiceListbox;	
	private TextBox queryTextBox;	
	private Button searchButton = new Button("Search");
	
	private Widget createMapsWidget(){
		map.setSize("500px", "300px");
		map.addControl(new LargeMapControl());
		LatLng startPoint  = LatLng.newInstance(19.01798, 72.844763);
		map.setCenter(startPoint, 12);
		return map;
	}
	private SuggestBox setUpCitySuggestBox(){
		ItemSuggestOracle oracle = new ItemSuggestOracle();
		oracle.setSuggestionType(CITY);
		citySuggestBox = new  SuggestBox(oracle);
		citySuggestBox.setText("Mumbai");
		
		return citySuggestBox;
	}
	private SuggestBox setUpLocationSuggestBox(){
		ItemSuggestOracle oracle = new ItemSuggestOracle();
		oracle.setSuggestionType(LOCATION);
		locationSuggestBox =new SuggestBox(oracle);
		return locationSuggestBox;
	}
	private SuggestBox setUpInterestSuggestBox(){
		ItemSuggestOracle oracle = new ItemSuggestOracle();
		oracle.setSuggestionType(INTEREST);
		interestSuggestBox =new SuggestBox(oracle);
		return interestSuggestBox;
	}
	
	private FlexTable createSearchCriteriaTable(){
		searchCriteriaTable.setText(0, 0, "City");
		searchCriteriaTable.setText(0, 1, "Location");
		searchCriteriaTable.setText(0, 2, "Interest");
		
		searchCriteriaTable.setWidget(1, 0, setUpCitySuggestBox());
		searchCriteriaTable.setWidget(1, 1, setUpLocationSuggestBox());
		searchCriteriaTable.setWidget(1, 2, setUpInterestSuggestBox());
		searchCriteriaTable.setWidget(1, 3, searchButton);
		return searchCriteriaTable;
	}
	private FlexTable createTopActivitiesTable(){
		topActivitiesTable.setText(0, 0, "Top Rated Activities");
		topActivitiesTable.setText(1,0,"Teach English");
		topActivitiesTable.setText(2,0,"Teach Guitar");
		topActivitiesTable.setText(3,0,"Self Defence");
		topActivitiesTable.setText(4,0,"Help with after school study");
		topActivitiesTable.setText(5,0,"Teach German");
		topActivitiesTable.setText(6,0,"Help build confidence");
		topActivitiesTable.setText(7,0,"Candle making");
		topActivitiesTable.setText(8,0,"Drawing");
		topActivitiesTable.setText(9,0,"Salsa");
		topActivitiesTable.getRowFormatter().addStyleName(0, "tableHeader");
		topActivitiesTable.setWidth("100%");
		return topActivitiesTable;
	}
	
	private FlexTable createTopVolunteersTable(){
		activeVolunteersTable.setText(0, 0, "Most Active Volunteers");
		activeVolunteersTable.setText(1,0,"Harpreet Singh");
		activeVolunteersTable.setText(2,0,"Shweta J");
		activeVolunteersTable.setText(3,0,"Pankaj D");
		activeVolunteersTable.setText(4,0,"Rishi Mishra");
		activeVolunteersTable.setText(5,0,"Vishal Rajpal");
		activeVolunteersTable.setWidth("100%");
		activeVolunteersTable.getRowFormatter().addStyleName(0, "tableHeader");
		return activeVolunteersTable;
	}
	
	private FlexTable createSearchResultsTable(){
		searchResultsTable.setText(0, 0, "School Name");
		searchResultsTable.setText(0, 1, "Address");
		searchResultsTable.setText(0, 2, "Activities");
		searchResultsTable.getRowFormatter().addStyleName(0, "tableHeader");
		searchResultsTable.setWidth("100%");
		return searchResultsTable;
	}
	public VolunteerView() {
		
	}
	
	
	public Panel createVolunteerView(){
		topRatedStuff.add(createTopActivitiesTable());
		topRatedStuff.add(createTopVolunteersTable());
		topRatedStuff.setWidth("100%");
		resultsPanel.add(createSearchResultsTable());
		resultsPanel.setWidth("100%");
		bottomHorizontalPanel.add(resultsPanel);
		bottomHorizontalPanel.add(topRatedStuff);
		bottomHorizontalPanel.setWidth("100%");
		mapsPanel.add(createMapsWidget());
		mapsPanel.setWidth("100%");
		topHorizontalPanel.add(mapsPanel);
		searchCriteriaPanel.add(createSearchCriteriaTable());
		searchCriteriaPanel.setWidth("100%");
		topHorizontalPanel.add(searchCriteriaPanel);
		topHorizontalPanel.setWidth("100%");
		baseVerticalPanel.add(topHorizontalPanel);
		baseVerticalPanel.add(bottomHorizontalPanel);
		baseVerticalPanel.setWidth("100%");
		baseVerticalPanel.setHeight(Window.getClientHeight()+"px");
		
		attachListeners();
		return baseVerticalPanel;
	}



	public TextArea getInfoTextArea() {
		return infoTextArea;
	}

	public Label getFindlabel() {
		return findlabel;
	}

	public ListBox getChoiceListbox() {
		return choiceListbox;
	}

	public TextBox getQueryTextBox() {
		return queryTextBox;
	}

	public Button getSearchButton() {
		return searchButton;
	}

	public Panel getResultsPanel() {
		return resultsPanel;
	}

	public void attachListeners(){
	}
	
	

}
